package com.it.listener;

import cn.hutool.core.lang.UUID;
import dev.langchain4j.model.chat.listener.ChatModelErrorContext;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
import dev.langchain4j.model.chat.listener.ChatModelResponseContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestChatModelListener implements ChatModelListener {
    @Override
    public void onRequest(ChatModelRequestContext requestContext){
        String replace = UUID.randomUUID().toString().replace("-", "");
        requestContext.attributes().put("requestId", replace);
        log.info("请求参数requestId:{}", replace);
    }
    @Override
    public void onResponse(ChatModelResponseContext responseContext){
        Object object = responseContext.attributes().get("requestId");
        log.info("响应参数requestId:{}", object);
    }
    @Override
    public void onError(ChatModelErrorContext errorContext){
        log.error("错误信息:{}", errorContext);
    }
}